<?php $count = 0; ?>

    <!DOCTYPE html>
    <html>
    <head>
        <title>An Error Occurred - <?php echo get_class($e); ?></title>

        <script type="text/javascript">
            <?php echo file_get_contents(__DIR__ . '/codemirror/lib/codemirror.js'); ?>
        </script>
        <script type="text/javascript">
            <?php echo file_get_contents(__DIR__ . '/codemirror/mode/php/php.js'); ?>
        </script>
        <script type="text/javascript">
            <?php echo file_get_contents(__DIR__ . '/codemirror/addon/selection/active-line.js'); ?>
        </script>

        <style type="text/css">
            body, html {
                background-color: #101010;
                font-family: helvetica, sans-serif, arial;
                padding: 0 0 20px 0;
                margin: 0;
            }

            .container {
                width: 920px;
                margin: 0 auto;
                background-color: #fff;
                border-radius: 10px;
                padding: 20px;
                box-shadow: 0px 0px 50px rgba(255, 255, 255, 0.2);
            }

            .block { background-color: #eee; padding: 20px; border-radius: 10px; color: #444; font-family: verdana; font-size: 13px; border: 1px solid #dfdfdf; }

            code.file { color: #aaa; font-size: 11px;}

            .title { width: 920px; margin: 0 auto; font-size: 28px; font-weight: normal; color: #fff;
                text-shadow: 0px 0px 25px rgba(255, 255, 255, 0.75); border-bottom: none; padding: 20px 0;
                border-bottom-left-radius: 20px; border-bottom-right-radius: 20px; }

            h2 { margin: 0; padding-bottom: 4px; color: darkred; font-weight: bold; border-bottom: 1px dotted #ddd; }

            hr { border:none; border-top: 1px solid #eee; border-bottom: 1px solid #fff}
        </style>
        <style type="text/css"><?php echo file_get_contents(__DIR__ . '/codemirror/lib/codemirror.css'); ?></style>
    </head>
    <body>
    <h2 class="title"><?php echo get_class($e); ?></h2>
    <div class="container">
        <div class="block">
            <?php echo $e->getMessage(); ?>
        </div>

        <br />

        <?php echo '<pre>', print_r($e->getTraceAsString()), '</pre>'; ?>

        <hr />
        <br />

        <code class="file"><?php echo $e->getFile() . ':' . $e->getLine(); ?></code>
        <textarea id="code<?php echo ++$count; ?>"><?php echo file_get_contents($e->getFile()); ?></textarea>
        <script type="text/javascript">
            var c = CodeMirror.fromTextArea(document.getElementById("code<?php echo $count; ?>"), {
                lineNumbers: true,
                mode: "text/x-php",
                readOnly: true
            });

            c.scrollIntoView(<?php echo $e->getLine()+10; ?>);
            c.setOption('activeLine', <?php echo $e->getLine()-1; ?>);
        </script>

        <?php foreach ($e->getTrace() as $trace):
            if (!isset($trace['file'])) continue;
            if ($count > 2) break;
            ?>
            <hr />
            <br />
            <code class="file"><?php echo $trace['file'] . ':' . $trace['line']; ?></code>
            <textarea id="code<?php echo ++$count; ?>"><?php echo file_get_contents($trace['file']); ?></textarea>
            <script type="text/javascript">
                var c = CodeMirror.fromTextArea(document.getElementById("code<?php echo $count; ?>"), {
                    lineNumbers: true,
                    mode: "text/x-php",
                    readOnly: true
                });

                c.scrollIntoView(<?php echo $trace['line']+10; ?>);
                c.setOption('activeLine', <?php echo $trace['line'] - 1; ?>);
            </script>
        <?php endforeach; ?>
    </div>

    </body>
    </html>

<?php

function getContent($file, $line, $offset = 12)
{
    $contents = file($file);

    $output = '';
    for ($i = $line - $offset; $i <= $line + $offset; $i++)
    {
        if (!isset($contents[$i])) continue;

        $output .= $contents[$i];
    }

    return $output;
}